package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.NationBasedataExCode;
import com.handydata.antifraud.bo.nationbasedata.NationBasedataReqBO;
import com.handydata.antifraud.bo.nationbasedata.NationBasedataResBO;
import com.handydata.antifraud.vo.nationbasedata.CreateNationBasedataReqVO;
import com.handydata.antifraud.vo.nationbasedata.CreateNationBasedataResVO;
import com.handydata.antifraud.vo.nationbasedata.DeleteNationBasedataReqVO;
import com.handydata.antifraud.vo.nationbasedata.DeleteNationBasedataResVO;
import com.handydata.antifraud.vo.nationbasedata.ModifyNationBasedataReqVO;
import com.handydata.antifraud.vo.nationbasedata.ModifyNationBasedataResVO;
import com.handydata.antifraud.vo.nationbasedata.NationBasedataBeanVO;
import com.handydata.antifraud.vo.nationbasedata.QueryNationBasedataReqVO;
import com.handydata.antifraud.vo.nationbasedata.QueryNationBasedataResVO;
import com.handydata.antifraud.service.NationBasedataService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/nationbasedata")
@RestController
public class NationBasedataController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(NationBasedataController.class);
	
	@Autowired
	private NationBasedataService nationBasedataService;
	
	@ApiOperation(value="新增民族码表", notes="新增民族码表")
	@ApiImplicitParam(name = "req", value = "新增民族码表请求对象", required = true, dataType = "CreateNationBasedataReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateNationBasedataResVO createNationBasedata(@RequestBody CreateNationBasedataReqVO req) {
		try {
			logger.info("Execute createNationBasedata, param is {}", req);
			NationBasedataReqBO reqBO = CommonBeanConvertor.convert(req, NationBasedataReqBO.class);
			NationBasedataResBO resBO = nationBasedataService.createNationBasedata(reqBO);
			CreateNationBasedataResVO res = CommonBeanConvertor.convert(resBO, CreateNationBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateNationBasedataResVO.class, req, NationBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改民族码表", notes="修改民族码表")
	@ApiImplicitParam(name = "req", value = "修改民族码表请求对象", required = true, dataType = "ModifyNationBasedataReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyNationBasedataResVO modifyNationBasedata(@RequestBody ModifyNationBasedataReqVO req) {
		try {
			logger.info("Execute modifyNationBasedata, param is {}", req);
			NationBasedataReqBO reqBO = CommonBeanConvertor.convert(req, NationBasedataReqBO.class);
			NationBasedataResBO resBO = nationBasedataService.modifyNationBasedata(reqBO);
			ModifyNationBasedataResVO res = CommonBeanConvertor.convert(resBO, ModifyNationBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyNationBasedataResVO.class, req, NationBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除民族码表", notes="删除民族码表")
	@ApiImplicitParam(name = "req", value = "修改民族码表请求对象", required = true, dataType = "DeleteNationBasedataReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteNationBasedataResVO deleteNationBasedata(@RequestBody DeleteNationBasedataReqVO req) {
		try {
			logger.info("Execute deleteNationBasedata, param is {}", req);
			NationBasedataReqBO reqBO = CommonBeanConvertor.convert(req, NationBasedataReqBO.class);
			NationBasedataResBO resBO = nationBasedataService.deleteNationBasedata(reqBO);
			DeleteNationBasedataResVO res = CommonBeanConvertor.convert(resBO, DeleteNationBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteNationBasedataResVO.class, req, NationBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询民族码表", notes="查询民族码表")
	@ApiImplicitParam(name = "req", value = "查询民族码表请求对象", required = true, dataType = "QueryNationBasedataReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryNationBasedataResVO queryNationBasedata(@RequestBody QueryNationBasedataReqVO req) {
		try {
			logger.info("Execute queryNationBasedata, param is {}", req);
			NationBasedataReqBO reqBO = CommonBeanConvertor.convert(req, NationBasedataReqBO.class);
			NationBasedataResBO resBO = nationBasedataService.queryNationBasedata(reqBO);
			QueryNationBasedataResVO res = CommonBeanConvertor.convert(resBO, QueryNationBasedataResVO.class, NationBasedataBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryNationBasedataResVO.class, req, NationBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
